#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    connect(ui->push_button_01, &QPushButton::clicked, this, [=]() {
        // 打开一个文件夹, 并获取文件夹的路径
        QString pathname = QFileDialog::getExistingDirectory(this, "Open Dir", "D:\\Desktop");
        qDebug() << pathname << endl;
    });

    connect(ui->push_button_02, &QPushButton::clicked, this, [=]() {
        // 打开一个过滤文件， 并获取文件的路径
        QString pathname = QFileDialog::getOpenFileName(this, "Open File", "D\\Desktop", "Image (*.png *.jpg);;File (*.txt)");
        qDebug() << pathname << endl;
    });

    connect(ui->push_button_03, &QPushButton::clicked, this, [=]() {
        // 打开多个过滤文件， 并获取文件列表的路径
        QStringList pathname_list = QFileDialog::getOpenFileNames(this, "Open Files", "D\\Desktop", "Image (*.png *.jpg);;File (*.txt)");
        for (int i = 0; i < pathname_list.size(); i++) {
            qDebug() << "pathname = " << pathname_list[i] << endl;
        }
    });

    connect(ui->push_button_04, &QPushButton::clicked, this, [=]() {
        // 保存或替换一个文件, 这种保存是界面上的保存或替换, 后续文件的修改需要实际的后台操作
        QString pathname = QFileDialog::getSaveFileName(this, "Save File", "D:\\Desktop");
        qDebug() << "pathname = " << pathname << endl;

        // 实际的后台操作...
    });
}

Widget::~Widget()
{
    delete ui;
}

